<!--
 * @Author: daifen
 * @Date: 2020-07-07 14:32:56
 * @LastEditors: daifen
--> 
<template>
  <div>
    <el-button type="primary" @click="submitForm" class="mt-10 ml-10"
      >保存</el-button
    >
    <el-button type="primary" @click="handleGoback" class="mt-10 ml-10"
      >返回</el-button
    >
    <el-form ref="form" :model="form" :rules="rules" label-width="200px">
      <el-row :gutter="10">
        <el-col :span="8">
          <el-form-item label="模板名称" prop="name">
            <el-input v-model="form.name" placeholder="请输入模板名称" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="目标包路径" prop="targetPackage">
            <el-input
              v-model="form.targetPackage"
              placeholder="请输入目标包路径"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="文件名称" prop="fileName">
            <el-input v-model="form.fileName" placeholder="请输入目标包路径" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="方案ID" prop="schemeId">
            <!-- <common-get-select
              v-model="form.schemeId"
              fieldName="title"
              keyFieldName="id"
              tableName="gen_template_scheme"
              whereSql
              style="padding: 0px"
            /> -->
            <el-select placeholder="请选择模板类型" v-model="form.schemeId">
              <el-option
                v-for="dict in schemeOptions"
                :key="dict.id"
                :label="dict.title"
                :value="dict.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="模板类型">
            <el-select v-model="form.templateType" placeholder="请选择模板类型">
              <el-option
                v-for="dict in templateTypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item
        label="模板内容"
        prop="templateContent"
        style="margin-bottom: 200px"
      >
        <!-- <el-input v-model="form.templateContent" type="textarea" placeholder="请输入内容" /> -->
        <!-- <Editor v-model="form.templateContent" /> -->
        <textarea
          v-model="form.templateContent"
          name
          id
          cols="300"
          rows="50"
        ></textarea>
        <!-- <in-editor v-model="form.templateContent"></in-editor> -->
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import {addTemplate, updateTemplate,} from "@/api/gen/template";
  import Editor from "@/components/Editor";
  import {getSelect} from "@/api/system/duplicate";
  // import CommonGetSelect from "@/components/df/commonGetSelect";
// import inEditor from "@/components/inEditor";
export default {
  data() {
    return {
      // 表单参数
      form: {
        id: null, //主键

        name: null, //模板名称

        fileName: null, //是否是class

        targetPackage: null, //目标包路径

        templateContent: null, //模板内容

        schemeId: null, //方案ID

        delFlag: null, //删除标志（0代表存在 2代表删除）

        createBy: null, //创建者

        createTime: null, //创建时间

        updateBy: null, //更新者

        updateTime: null, //更新时间

        templateType: null, //模板类型
      },
      templateTypeOptions: [],
      schemeOptions: [],
    };
  },
  created() {
    //获取上页传递过来的参数
    this.form = this.$route.query.form;
    this.getDicts("gen_type").then((response) => {
      this.templateTypeOptions = response.data;
    });

    getSelect().then((res) => {
      this.schemeOptions = res.data;
    });
  },
  components: {
    Editor,
    // CommonGetSelect
    // inEditor
  },
  methods: {
    //返回上一页
    handleGoback() {
      this.$router.go(-1);
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            updateTemplate(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                // this.open = false;
                // this.getList();
                this.$router.go(-1);
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addTemplate(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                // this.open = false;
                // this.getList();
                this.$router.go(-1);
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.mt-10 {
  margin-top: 10px;
}

.ml-10 {
  margin-left: 10px;
}

.querySelect {
  padding: 0 !important;
  width: 100% !important;
}
</style>
